package service.impl;

import bean.RoomBean;
import mapper.IRoomMapper;
import org.apache.ibatis.session.SqlSession;
import service.IRoomService;

import java.util.List;

public class RoomServiceImpl extends BaseService implements IRoomService {
    @Override
    public void add(RoomBean room) {
        //得到会话
        SqlSession session = this.getSession();
        //得到mapper接口实体类对象
        IRoomMapper mapper = session.getMapper(IRoomMapper.class);
        //执行持久方法，完成操作
        mapper.add(room);
        //提交事务
        session.commit();
        //关闭session
        session.close();
    }

    @Override
    public void del(Integer id) {
        SqlSession session = this.getSession();
        IRoomMapper mapper = session.getMapper(IRoomMapper.class);
        mapper.del(id);
        session.commit();
        session.close();
    }

    @Override
    public void update(Integer id, int price) {
        SqlSession session = this.getSession();
        IRoomMapper mapper = session.getMapper(IRoomMapper.class);
        mapper.update(id,price);
        session.commit();
        session.close();
    }

    @Override
    public List<RoomBean> findAll() {
        SqlSession session = this.getSession();
        IRoomMapper mapper = session.getMapper(IRoomMapper.class);
        List<RoomBean>list=mapper.findAll();
        session.close();
        return list;
    }

    @Override
    public RoomBean findById(Integer id) {
        SqlSession session = this.getSession();
        IRoomMapper mapper = session.getMapper(IRoomMapper.class);
        RoomBean roomBean=mapper.findById(id);
        session.close();
        return roomBean;
    }
}
